package com.three.iot.rest.controller.admin;

import com.three.iot.api.UserDeviceService;
import com.three.iot.commons.enums.Result;
import com.three.iot.commons.enums.ResultCode;
import com.three.iot.rest.controller.common.AbstractDeviceAttrController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author luiz
 * @Title: DeviceController
 * @ProjectName iot-server
 * @Description: TODO
 * @date 2019-05-14 14:45
 */
@RestController
@RequestMapping("/admin/userDevice")
@Api(tags = "用户设备信息api")
public class SysUserDeviceController extends AbstractDeviceAttrController {
    private static final Logger logger = LoggerFactory.getLogger(SysUserDeviceController.class);
    @Resource
    private UserDeviceService userDeviceService;

    /**
     * 按照用户编号查询所有设备 包含绑定状态
     * 按照用户编号、用户主键ID查询
     */
    @ApiOperation(value = "按照用户编号查询所有设备 包含绑定状态", notes = "按照用户编号查询所有设备 包含绑定状态")
    @GetMapping("/findDeviceByUserNo/{userNo}")
    public Result findDeviceByUserNo(@PathVariable("userNo") String userNo) {
        try {
            return userDeviceService.findDeviceByUserNo(userNo);
        } catch (Exception e) {
            logger.error("按照用户编号查询所有设备 包含绑定状态 异常:{}", e);
            return Result.newError(ResultCode.FAIL);
        }

    }
    /**
     * 按照设备编号查询所有用户信息 包含绑定状态
     */
    @ApiOperation(value = "按照设备编号查询所有用户信息 包含绑定状态", notes = "按照设备编号查询所有用户信息 包含绑定状态")
    @GetMapping("/findUserByDeviceId/{iotId}")
    public Result findUserByDeviceId(@PathVariable("iotId") String iotId) {
        try {
            return userDeviceService.findUserByDeviceId(iotId);
        } catch (Exception e) {
            logger.error("按照设备编号查询所有用户信息 包含绑定状态 异常:{}", e);
            return Result.newError(ResultCode.FAIL);
        }

    }

}
